package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Department;
import cn.wolfcode.crm.mapper.DepartmentMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IDepartmentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepartmentServiceImpl implements IDepartmentService {

	@Autowired
	@SuppressWarnings("all")
	private DepartmentMapper departmentMapper;

	@Override
	public void delete(Long id) {
		departmentMapper.deleteByPrimaryKey(id);
	}

	@Override
	public void save(Department department) {
		departmentMapper.insert(department);
	}

	@Override
	public Department get(Long id) {
		return departmentMapper.selectByPrimaryKey(id);
	}

	@Override
	public List<Department> listAll() {
		return departmentMapper.selectAll();
	}

	@Override
	public void update(Department department) {
		departmentMapper.updateByPrimaryKey(department);
	}

	@Override
	public PageInfo query(QueryObject qo) {
		//参数为当前页 ,每页多少条数据
		PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
		List<Department> departments = departmentMapper.queryForList(qo);
		return new PageInfo(departments);
	}
}
